<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="js/jquery-3.2.1.min.js"></script>
		<script type="application/javascript">
			$(function(){
				$("#btn").click(function(){
					var total = $("#total").val();
					var kick = $("#kick").val();
					var monkey=[];
					//保存猴子的编号，monkey[0]=1
					for(var i=1;i<=total;i++){
						monkey.push(i);
					}
					i=1;
					while(monkey.length>1){
						var head = monkey.shift();//移出最前面的编号
						if(i%kick != 0){
							monkey.push(head);
						}
						i++;
					}
					$("#king").val(monkey[0]);
				})
			})
			
		</script>
	</head>
	<body>
		<div>
			<label for="total">猴子的总数:</label>
			<input type="text" name="total" id="total" value="" />
			<br />
			<label for="kick">踢出猴子编号:</label>
			<input type="text" name="kick" id="kick" value=""/>
			<br />
			<label for="king">大王:</label>
			<input type="text" name="king" id="king" value="" disabled=""/>
			<br />
			<input type="button" value="开始选大王" id="btn"/>
		</div>
	</body>
</html>
